package com.taotao.rest;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;

@SpringBootApplication
@MapperScan(basePackages = "com.taotao.mapper")
public class RestApplication {
    public static void main(String[] args) {
        SpringApplication.run(RestApplication.class,args);
    }


    @Primary
    @Bean("myRedisTemplate")
    public RedisTemplate myRedisTemplate(RedisTemplate redisTemplate){
        redisTemplate.setHashKeySerializer(RedisSerializer.string());
        redisTemplate.setKeySerializer(RedisSerializer.string());

//        redisTemplate.setHashValueSerializer(RedisSerializer.java());
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer(new ObjectMapper()));
//        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }
}
